﻿using Ekton_Manage_DomainCore.Aggregate;
using Ekton_Manage_DTO.APIRequestModels.SysUser;
using Ekton_Manage_DTO.RequestModels;
using Ekton_Manage_DTO.RequestModels.SysUser;
using Ekton_Manage_DTO.RequestModels.User;
using Ekton_Manage_Framework.Methods;
using Ekton_Manage_IBusiness;
using Ekton_Manage_InfrastructureCore.Common;
using Ekton_Manage_InfrastructureCore.Repositories;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;


namespace Ekton_Manage_Business
{

    public class APIagreement : IApiAgreement
    {

        private readonly SerializeParameter _serialize;
        private readonly IBaseRepository<sys_msg, int> _baseMaterialRepository;

        public APIagreement(SerializeParameter serialize, IBaseRepository<sys_msg, int> baseMaterialRepository)
        {

            _serialize = serialize;
            _baseMaterialRepository = baseMaterialRepository;
        }


        //查看隐私&协议条款
        public async Task<Message> SelectAgreement()
        {
            var res = await _baseMaterialRepository.QueryTableList(m=>true);
            return new Message(res);
        }

        /// <summary>
        /// 修改隐私协议条款
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<Message> PutAgreementList(ApiDtoAgreement request)
        {
            var res = await _baseMaterialRepository.QuerySingleData(request.id);
            if (res is null) return new Message("没有该隐私协议条款信息",false,202);
            res.deal = request.deal;
            res.about_us = request.about_us;
            res.url = request.url;
            var results = await _baseMaterialRepository.UpdateSingleData(res);
            return new Message(results);
        }
    }
}
